/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package bpmn.impl;

import bpmn.AdHocOrderingTypes;
import bpmn.BpmnPackage;
import bpmn.Embedded;
import bpmn.Expression;
import bpmn.GraphicalElement;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Embedded</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link bpmn.impl.EmbeddedImpl#getGraphicalElements <em>Graphical Elements</em>}</li>
 *   <li>{@link bpmn.impl.EmbeddedImpl#getAdHoc <em>Ad Hoc</em>}</li>
 *   <li>{@link bpmn.impl.EmbeddedImpl#getAdHocOrdering <em>Ad Hoc Ordering</em>}</li>
 *   <li>{@link bpmn.impl.EmbeddedImpl#getAdHocCompletionCondition <em>Ad Hoc Completion Condition</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class EmbeddedImpl extends SubProcessImpl implements Embedded {
	/**
	 * The cached value of the '{@link #getGraphicalElements() <em>Graphical Elements</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getGraphicalElements()
	 * @generated
	 * @ordered
	 */
	protected EList<GraphicalElement> graphicalElements;

	/**
	 * The default value of the '{@link #getAdHoc() <em>Ad Hoc</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAdHoc()
	 * @generated
	 * @ordered
	 */
	protected static final Boolean AD_HOC_EDEFAULT = Boolean.FALSE;

	/**
	 * The cached value of the '{@link #getAdHoc() <em>Ad Hoc</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAdHoc()
	 * @generated
	 * @ordered
	 */
	protected Boolean adHoc = AD_HOC_EDEFAULT;

	/**
	 * The default value of the '{@link #getAdHocOrdering() <em>Ad Hoc Ordering</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAdHocOrdering()
	 * @generated
	 * @ordered
	 */
	protected static final AdHocOrderingTypes AD_HOC_ORDERING_EDEFAULT = AdHocOrderingTypes.SEQUENTIAL;

	/**
	 * The cached value of the '{@link #getAdHocOrdering() <em>Ad Hoc Ordering</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAdHocOrdering()
	 * @generated
	 * @ordered
	 */
	protected AdHocOrderingTypes adHocOrdering = AD_HOC_ORDERING_EDEFAULT;

	/**
	 * The cached value of the '{@link #getAdHocCompletionCondition() <em>Ad Hoc Completion Condition</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAdHocCompletionCondition()
	 * @generated
	 * @ordered
	 */
	protected Expression adHocCompletionCondition;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected EmbeddedImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return BpmnPackage.Literals.EMBEDDED;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<GraphicalElement> getGraphicalElements() {
		if (graphicalElements == null) {
			graphicalElements = new EObjectContainmentEList<GraphicalElement>(GraphicalElement.class, this, BpmnPackage.EMBEDDED__GRAPHICAL_ELEMENTS);
		}
		return graphicalElements;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Boolean getAdHoc() {
		return adHoc;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setAdHoc(Boolean newAdHoc) {
		Boolean oldAdHoc = adHoc;
		adHoc = newAdHoc;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, BpmnPackage.EMBEDDED__AD_HOC, oldAdHoc, adHoc));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public AdHocOrderingTypes getAdHocOrdering() {
		return adHocOrdering;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setAdHocOrdering(AdHocOrderingTypes newAdHocOrdering) {
		AdHocOrderingTypes oldAdHocOrdering = adHocOrdering;
		adHocOrdering = newAdHocOrdering == null ? AD_HOC_ORDERING_EDEFAULT : newAdHocOrdering;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, BpmnPackage.EMBEDDED__AD_HOC_ORDERING, oldAdHocOrdering, adHocOrdering));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Expression getAdHocCompletionCondition() {
		if (adHocCompletionCondition != null && adHocCompletionCondition.eIsProxy()) {
			InternalEObject oldAdHocCompletionCondition = (InternalEObject)adHocCompletionCondition;
			adHocCompletionCondition = (Expression)eResolveProxy(oldAdHocCompletionCondition);
			if (adHocCompletionCondition != oldAdHocCompletionCondition) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, BpmnPackage.EMBEDDED__AD_HOC_COMPLETION_CONDITION, oldAdHocCompletionCondition, adHocCompletionCondition));
			}
		}
		return adHocCompletionCondition;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Expression basicGetAdHocCompletionCondition() {
		return adHocCompletionCondition;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setAdHocCompletionCondition(Expression newAdHocCompletionCondition) {
		Expression oldAdHocCompletionCondition = adHocCompletionCondition;
		adHocCompletionCondition = newAdHocCompletionCondition;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, BpmnPackage.EMBEDDED__AD_HOC_COMPLETION_CONDITION, oldAdHocCompletionCondition, adHocCompletionCondition));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case BpmnPackage.EMBEDDED__GRAPHICAL_ELEMENTS:
				return ((InternalEList<?>)getGraphicalElements()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case BpmnPackage.EMBEDDED__GRAPHICAL_ELEMENTS:
				return getGraphicalElements();
			case BpmnPackage.EMBEDDED__AD_HOC:
				return getAdHoc();
			case BpmnPackage.EMBEDDED__AD_HOC_ORDERING:
				return getAdHocOrdering();
			case BpmnPackage.EMBEDDED__AD_HOC_COMPLETION_CONDITION:
				if (resolve) return getAdHocCompletionCondition();
				return basicGetAdHocCompletionCondition();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case BpmnPackage.EMBEDDED__GRAPHICAL_ELEMENTS:
				getGraphicalElements().clear();
				getGraphicalElements().addAll((Collection<? extends GraphicalElement>)newValue);
				return;
			case BpmnPackage.EMBEDDED__AD_HOC:
				setAdHoc((Boolean)newValue);
				return;
			case BpmnPackage.EMBEDDED__AD_HOC_ORDERING:
				setAdHocOrdering((AdHocOrderingTypes)newValue);
				return;
			case BpmnPackage.EMBEDDED__AD_HOC_COMPLETION_CONDITION:
				setAdHocCompletionCondition((Expression)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case BpmnPackage.EMBEDDED__GRAPHICAL_ELEMENTS:
				getGraphicalElements().clear();
				return;
			case BpmnPackage.EMBEDDED__AD_HOC:
				setAdHoc(AD_HOC_EDEFAULT);
				return;
			case BpmnPackage.EMBEDDED__AD_HOC_ORDERING:
				setAdHocOrdering(AD_HOC_ORDERING_EDEFAULT);
				return;
			case BpmnPackage.EMBEDDED__AD_HOC_COMPLETION_CONDITION:
				setAdHocCompletionCondition((Expression)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case BpmnPackage.EMBEDDED__GRAPHICAL_ELEMENTS:
				return graphicalElements != null && !graphicalElements.isEmpty();
			case BpmnPackage.EMBEDDED__AD_HOC:
				return AD_HOC_EDEFAULT == null ? adHoc != null : !AD_HOC_EDEFAULT.equals(adHoc);
			case BpmnPackage.EMBEDDED__AD_HOC_ORDERING:
				return adHocOrdering != AD_HOC_ORDERING_EDEFAULT;
			case BpmnPackage.EMBEDDED__AD_HOC_COMPLETION_CONDITION:
				return adHocCompletionCondition != null;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (AdHoc: ");
		result.append(adHoc);
		result.append(", AdHocOrdering: ");
		result.append(adHocOrdering);
		result.append(')');
		return result.toString();
	}

} //EmbeddedImpl
